package com.qrcode.service.impl.user;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qrcode.beans.user.User;
import com.qrcode.mapper.UserMapper;
import com.qrcode.service.IUserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;
import java.util.List;

/**
 * @Author: yzx96
 * @CreateTime: 2019-09-29 22:13
 * @Description: ${Description}
 */
@Service(group = "qrcode")
public class UserServiceImpl implements IUserService {

    private Logger logger = Logger.getLogger(UserServiceImpl.class);

    @Autowired
    private UserMapper userMapper;

    public List<User> getUser() {
        return userMapper.getUser();
    }

    /**
     * 分页查询用户
     * @param page 页码
     * @param size 数量
     * @return
     */
    public PageInfo<User> getUsersLimit(int page,int size){
        logger.info("开始分页查询用户信息");
        //首先开启PageHelper的分页
        PageHelper.startPage(page, size);
        //查询分页信息 调用方式与普通方式一致
        List<User> list=userMapper.getUser();
        //生成PageInfo对象
        PageInfo<User> pageInfo=new PageInfo<User>(list);
        //总数据条数
        System.out.println(pageInfo.getTotal());
        //第一页的页码
        System.out.println(pageInfo.getFirstPage());
        //最终页的页码
        System.out.println(pageInfo.getLastPage());
        //下一页的页码
        System.out.println(pageInfo.getNextPage());
        //当前页码
        System.out.println(pageInfo.getPageNum());
        //开始的数据下标
        System.out.println(pageInfo.getStartRow());
        //结束的数据下标
        System.out.println(pageInfo.getEndRow());
        //数据条数
        System.out.println(pageInfo.getSize());
        logger.info("开始分页查询用户信息"+pageInfo.getList());
        return pageInfo;
    }
}
